﻿using suirui.ZhuMu.Model;
using suirui.ZhuMu.Repositories;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace suirui.ZhuMu.Services
{
    public class BaseServices<TEntity> : IBaseServices<TEntity> where TEntity : class, new()
    {
        public IBaseRepository<TEntity> _BaseRepository;
        public BaseServices(IBaseRepository<TEntity> baseRepository)
        {
            this._BaseRepository = baseRepository ;
        }

        public bool Any(Expression<Func<TEntity, bool>> whereLambd)
        {
            return _BaseRepository.Any(whereLambd);
        }

        public long Count(Expression<Func<TEntity, bool>> predicate = null)
        {
            return _BaseRepository.Count(predicate);
        }

        public Task<long> CountAsync(Expression<Func<TEntity, bool>> predicate = null)
        {
            return _BaseRepository.CountAsync(predicate);
        }

        public bool Delete(List<TEntity> entitys, bool isSaveChange = true)
        {
            return _BaseRepository.Delete(entitys, isSaveChange);
        }

        public bool Delete(TEntity entity, bool isSaveChange = true)
        {
            return _BaseRepository.Delete(entity, isSaveChange);
        }

        public Task<bool> DeleteAsync(List<TEntity> entitys, bool isSaveChange = true)
        {
            return _BaseRepository.DeleteAsync(entitys, isSaveChange);
        }

        public Task<bool> DeleteAsync(TEntity entity, bool isSaveChange = true)
        {
            return _BaseRepository.DeleteAsync(entity, isSaveChange);
        }

        public void Disposed()
        {
            _BaseRepository.Disposed();
        }

        public TEntity Get(Expression<Func<TEntity, bool>> predicate = null, bool isNoTracking = true)
        {
            return _BaseRepository.Get(predicate, isNoTracking);
        }

        public TEntity Get(object id)
        {
            return _BaseRepository.Get(id);
        }

        public Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> predicate = null, bool isNoTracking = true)
        {
            return _BaseRepository.GetAsync(predicate, isNoTracking);
        }

        public Task<TEntity> GetAsync(object id)
        {
            return _BaseRepository.GetAsync(id);
        }

        public List<TEntity> GetList(Expression<Func<TEntity, bool>> predicate = null, string ordering = "", bool isNoTracking = true)
        {
            return _BaseRepository.GetList(predicate, ordering, isNoTracking);
        }

        public Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate = null, string ordering = "", bool isNoTracking = true)
        {
            return _BaseRepository.GetListAsync(predicate, ordering, isNoTracking);
        }

        public PageData<TEntity> GetPage(Expression<Func<TEntity, bool>> whereLambda, string ordering, int pageIndex, int pageSize, bool isNoTracking = true)
        {
            return _BaseRepository.GetPage(whereLambda, ordering, pageIndex, pageSize, isNoTracking);
        }

        public Task<PageData<TEntity>> GetPageAsync(Expression<Func<TEntity, bool>> whereLambda, string ordering, int pageIndex, int pageSize, bool isNoTracking = true)
        {
            return _BaseRepository.GetPageAsync(whereLambda, ordering, pageIndex, pageSize, isNoTracking);
        }

        public Task<PageData<TEntity>> GetPageAsync<TKey>(Expression<Func<TEntity, bool>> whereLambda, Expression<Func<TEntity, TKey>> orderBy, int pageIndex, int pageSize, bool isOrder = true, bool isNoTracking = true)
        {
            return _BaseRepository.GetPageAsync(whereLambda, orderBy, pageIndex, pageSize, isOrder, isNoTracking);
        }

        public bool Insert(List<TEntity> entitys, bool isSaveChange = true)
        {
            return _BaseRepository.Insert(entitys, isSaveChange);
        }

        public bool Insert(TEntity entity, bool isSaveChange = true)
        {
            return _BaseRepository.Insert(entity, isSaveChange);
        }

        public Task<bool> InsertAsync(List<TEntity> entitys, bool isSaveChange = true)
        {
            return _BaseRepository.InsertAsync(entitys, isSaveChange);
        }

        public Task<bool> InsertAsync(TEntity entity, bool isSaveChange = true)
        {
            return _BaseRepository.InsertAsync(entity, isSaveChange);
        }

        public IQueryable<TEntity> Load(Expression<Func<TEntity, bool>> predicate = null, bool isNoTracking = true)
        {
            return _BaseRepository.Load(predicate, isNoTracking);
        }

        public Task<IQueryable<TEntity>> LoadAsync(Expression<Func<TEntity, bool>> predicate = null, bool isNoTracking = true)
        {
            return _BaseRepository.LoadAsync(predicate, isNoTracking);
        }

        public int SaveChanges()
        {
            return _BaseRepository.SaveChanges();
        }

        public Task<int> SaveChangesAsync()
        {
            return _BaseRepository.SaveChangesAsync();
        }

        public bool Update(List<TEntity> entitys, bool isSaveChange = true)
        {
            return _BaseRepository.Update(entitys, isSaveChange);
        }

        public bool Update(TEntity entity, bool isSaveChange = true, List<string> updatePropertyList = null, bool modified = true)
        {
            return _BaseRepository.Update(entity, isSaveChange, updatePropertyList, modified);
        }

        public Task<bool> UpdateAsync(List<TEntity> entitys, bool isSaveChange = true)
        {
            return _BaseRepository.UpdateAsync(entitys, isSaveChange);
        }

        public Task<bool> UpdateAsync(TEntity entity, bool isSaveChange = true, List<string> updatePropertyList = null, bool modified = true)
        {
            return _BaseRepository.UpdateAsync(entity, isSaveChange, updatePropertyList, modified);
        }
    }

}
